package com.weibo.net;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.share.ShareHandler;
import com.iknow.share.SinaWeibo;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.StringUtil;
import com.iknow.util.SystemUtil;
import com.mobclick.android.MobclickAgent;

public class ShareActivity extends Activity
{
  private View.OnClickListener BackClickListenr;
  private View.OnClickListener PostClickListenr;
  private int WEIBO_MAX_LENGTH;
  private String mContent;
  private EditText mEdit;
  private String mPicPath = "";
  private ImageView mPiclayout;
  private ProgressDialog mProgressDialog;
  private Button mSend;
  private ShareHandler mShareHandler;
  protected TaskListener mTaskListener;
  private TextView mTextNum;

  public ShareActivity()
  {
    this.mContent = "";
    this.WEIBO_MAX_LENGTH = 140;
    this.BackClickListenr = new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    };
    this.PostClickListenr = new View.OnClickListener(this)
    {
      public void onClick()
      {
        ShareActivity.access$0(this.this$0);
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "PostWeiboTask";
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        ShareActivity.access$1(this.this$0).dismiss();
        if (paramTaskResult != TaskResult.OK)
          Toast.makeText(this.this$0, "发布失败", 0).show();
        while (true)
        {
          return;
          Toast.makeText(this.this$0, "发布成功", 0).show();
          this.this$0.finish();
        }
      }

      public void onPreExecute()
      {
        if (ShareActivity.access$1(this.this$0) == null)
          ShareActivity.access$2(this.this$0, new ProgressDialog(this.this$0));
        ShareActivity.access$1(this.this$0).setMessage("正在发布，请稍后");
        ShareActivity.access$1(this.this$0).show();
      }
    };
  }

  private void checkTextLength()
  {
    int i = StringUtil.getStringLength(this.mEdit.getText().toString());
    if (i <= this.WEIBO_MAX_LENGTH)
    {
      int k = this.WEIBO_MAX_LENGTH - i;
      this.mTextNum.setTextColor(2131165185);
      if (!(this.mSend.isEnabled()))
        this.mSend.setEnabled(true);
      Object[] arrayOfObject2 = new Object[1];
      arrayOfObject2[0] = Integer.valueOf(k);
      String str2 = String.format("还可输入%d个字", arrayOfObject2);
      this.mTextNum.setText(str2);
    }
    while (true)
    {
      return;
      int j = i - this.WEIBO_MAX_LENGTH;
      this.mTextNum.setTextColor(-65536);
      if (this.mSend.isEnabled())
        this.mSend.setEnabled(false);
      Object[] arrayOfObject1 = new Object[1];
      arrayOfObject1[0] = Integer.valueOf(j);
      String str1 = String.format("已经超过%d个字", arrayOfObject1);
      this.mTextNum.setText(str1);
    }
  }

  private void initView()
  {
    ((Button)findViewById(2131296342)).setOnClickListener(this.BackClickListenr);
    this.mSend = ((Button)findViewById(2131296344));
    this.mSend.setText("发布");
    this.mSend.setOnClickListener(this.PostClickListenr);
    this.mTextNum = ((TextView)findViewById(2131296533));
    this.mEdit = ((EditText)findViewById(2131296531));
    if (SystemUtil.getDisplayHeight() < 480)
    {
      this.mEdit.setMaxLines(6);
      this.mEdit.addTextChangedListener(new TextWatcher(this)
      {
        public void afterTextChanged()
        {
        }

        public void beforeTextChanged(, int paramInt1, int paramInt2, int paramInt3)
        {
        }

        public void onTextChanged(, int paramInt1, int paramInt2, int paramInt3)
        {
          ShareActivity.access$6(this.this$0);
        }
      });
      this.mEdit.setText(this.mContent);
      this.mPiclayout = ((ImageView)findViewById(2131296534));
      if (!(TextUtils.isEmpty(this.mPicPath)))
        break label168;
      this.mPiclayout.setVisibility(8);
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          checkTextLength();
          return;
          this.mEdit.setMaxLines(10);
        }
        label168: this.mPiclayout.setVisibility(0);
        if (StringUtil.isEmpty(this.mPicPath))
          break;
        IKnow.mProfileImageCacheManager.displayContentBimap(this.mPiclayout, this.mPicPath);
      }
      this.mPiclayout.setVisibility(8);
    }
  }

  private void onUri()
  {
    int i = IKnow.mSystemConfig.getInt("share_type");
    Uri localUri = getIntent().getData();
    switch (i)
    {
    case 2:
    case 3:
    default:
    case 1:
    }
    while (true)
    {
      return;
      this.mShareHandler = new SinaWeibo();
      this.mShareHandler.onUriCompleteEvent(localUri, this);
      ((TextView)findViewById(2131296343)).setText("分享到新浪微博");
      this.WEIBO_MAX_LENGTH = this.mShareHandler.getMaxTextCount();
    }
  }

  private void postWeibo()
  {
    MobclickAgent.onEvent(this, "weibo_share");
    this.mContent = this.mEdit.getText().toString();
    PostWeiboTask localPostWeiboTask = new PostWeiboTask(this, null);
    localPostWeiboTask.setListener(this.mTaskListener);
    localPostWeiboTask.execute(new TaskParams[0]);
  }

  public void onCreate(Bundle paramBundle)
  {
    requestWindowFeature(1);
    super.onCreate(paramBundle);
    setContentView(2130903127);
    this.mContent = IKnow.mSystemConfig.getString("weibo_content");
    this.mPicPath = IKnow.mSystemConfig.getString("weibo_picture");
    initView();
    onUri();
  }

  protected void onPause()
  {
    MobclickAgent.onPause(this);
    super.onPause();
  }

  protected void onResume()
  {
    MobclickAgent.onResume(this);
    MobclickAgent.setSessionContinueMillis(600000L);
    super.onResume();
  }

  private class PostWeiboTask extends GenericTask
  {
    protected TaskResult _doInBackground()
    {
      TaskResult localTaskResult;
      try
      {
        ShareActivity.access$3(this.this$0).share(this.this$0, ShareActivity.access$4(this.this$0), ShareActivity.access$5(this.this$0));
        localTaskResult = TaskResult.OK;
        return localTaskResult;
      }
      catch (Exception localException)
      {
        localTaskResult = TaskResult.FAILED;
      }
    }
  }
}